package cn.edu.scau.cmi.liangzaoqing.client.classicsDesignPattern;

import java.util.Iterator;
import java.util.Set;

import cn.edu.scau.cmi.liangzaoqing.composite.consistent.ConsistentComponent;
import cn.edu.scau.cmi.liangzaoqing.composite.consistent.ConsistentComposite;
import cn.edu.scau.cmi.liangzaoqing.composite.consistent.ConsistentLeaf;

public class ConsistentCompositeClient {

	public static void main(String[] args) {
		
		ConsistentComponent trunk=new ConsistentComposite();
		((ConsistentComposite)trunk).setName("树干");
		

		ConsistentComponent firstBranch=new ConsistentComposite();
		((ConsistentComposite)firstBranch).setName("第一个树枝");
		
		
		ConsistentComponent secondBranch=new ConsistentComposite();
		((ConsistentComposite)secondBranch).setName("第二个树枝");
		
		
		
		
		ConsistentComponent firstLeaf=new ConsistentLeaf();
		((ConsistentLeaf)firstLeaf).setName("第一个树枝上的第一片树叶");
		
		ConsistentComponent secondLeaf=new ConsistentLeaf();
		((ConsistentLeaf)secondLeaf).setName("第一个树枝上的第二片树叶");
		
		
		ConsistentComponent thirdLeaf=new ConsistentLeaf();
		((ConsistentLeaf)thirdLeaf).setName("第二个树枝上的第一片树叶");
		
		ConsistentComponent forthLeaf=new ConsistentLeaf();
		((ConsistentLeaf)forthLeaf).setName("第二个树枝上的第二片树叶");
		
//		语法没问题。
		firstLeaf.addChild(secondLeaf);
		
		firstBranch.addChild(firstLeaf);
		firstBranch.addChild(secondLeaf);
		secondBranch.addChild(thirdLeaf);
		secondBranch.addChild(forthLeaf);
		
		trunk.addChild(firstBranch);
		trunk.addChild(secondBranch);
//		TODO 请同学们后面在作业中自己补充。
		Set<ConsistentComponent> trunkChildren = trunk.getChildren();
		Iterator<ConsistentComponent> trunkChildrenIterator = trunkChildren.iterator();
		
		
	
		System.out.println("添加完毕");
	}

}
